Skip to content

feat(dropdown): add opt-in close-on-click attribute#169

Open
Vikram-Hegde wants to merge 1 commit into
knadh:masterfrom
Vikram-Hegde:feat/dropdown-close-on-click
Open

feat(dropdown): add opt-in close-on-click attribute#169
Vikram-Hegde wants to merge 1 commit into
knadh:masterfrom
Vikram-Hegde:feat/dropdown-close-on-click

Conversation

@Vikram-Hegde

@Vikram-Hegde Vikram-Hegde commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in close-on-click attribute on <ot-dropdown> that automatically dismisses the popover as soon as a role="menuitem" is clicked.

Why

Previously, clicking a menu item inside a <ot-dropdown> popover did not close the popover — it only closed on an outside click or another toggle. For in-page actions (e.g. toggling a theme, muting a channel, switching a view) that don't trigger a navigation or page refresh, the dropdown stayed open and the user had to dismiss it manually. That made the menu feel sticky and broke the expected menu UX.

With close-on-click, the popover closes immediately on item click, giving the expected "menu item activates and the menu disappears" behavior — without forcing it on use cases that do rely on the popover staying open (e.g. forms, multi-step confirmations).

Usage

<ot-dropdown close-on-click>
  <button popovertarget="my-menu" class="outline">Options</button>
  <menu popover id="my-menu">
    <button role="menuitem">Profile</button>
    <button role="menuitem">Settings</button>
    <button role="menuitem">Help</button>
  </menu>
</ot-dropdown>

The default behavior is unchanged: the attribute is opt-in, and popovers without it still stay open on item click.

Add a `close-on-click` attribute on `<ot-dropdown>` that closes the
popover as soon as a `role="menuitem"` is clicked. Default behavior is
unchanged (popover stays open on item click).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant